package com.net.tomcat5.Servlet2;
import java.io.IOException;
import java.net.ServerSocket;

/**
 * 支持post请求
 *
 * @author jiangbang
 * @date 2016/8/24
 */
public class Server4 {
    private ServerSocket server;
    private boolean isShutdown = false;


    public static void main(String[] args) {
        Server4 server = new Server4();
        server.start(8888);
    }

    //启动方法
    public void start(int port){
        try {
            server = new ServerSocket(port);
            this.receive();
        } catch (IOException e) {
            stop();
        }
    }
    //结束方法
    public void stop(){
        isShutdown = true;
    }

    //接受客户端
    private void receive(){
        try {
            while (!isShutdown){
                new Thread(new Dispatcher(server.accept())).start();
            }
        } catch (IOException e) {
            stop();
        }
    }
}
